package org.ngrinder.demand.controller;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.ngrinder.model.TestRequirement;
import org.ngrinder.model.User;
import org.springframework.data.jpa.domain.Specification;

public abstract class TestRequirementSpecification {
	
	public static Specification<TestRequirement> idEmptyPredicate() {
		return new Specification<TestRequirement>() {
			@Override
			public Predicate toPredicate(Root<TestRequirement> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
				return root.get("id").isNotNull();
			}
		};
	}
	
	public static Specification<TestRequirement> createdBy(final User user) {
		return new Specification<TestRequirement>() {
			@Override
			public Predicate toPredicate(Root<TestRequirement> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
				return cb.or(cb.equal(root.get("createdUser"), user));
			}
		};
	}
}
